package com.jwiki.app.rpcui.extend;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;

public abstract class RunProcessThread implements IRunnableWithProgress {

    @Override
    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
        monitor.beginTask(getMessage(), IProgressMonitor.UNKNOWN);
        try {
            handleProcess(monitor);
        } catch (Exception e) {
            throw new InterruptedException(e.getMessage());
        }
        monitor.done();
        //if (monitor.isCanceled()) {
        //	throw new InterruptedException("Task has been canceled!");
        //}
    }

    public abstract String getMessage();

    public abstract void handleProcess(IProgressMonitor monitor) throws Exception;

}
